package com.dianping.cat.consumer.transaction.model.transform;
import com.dianping.cat.consumer.transaction.model.IVisitor;
import com.dianping.cat.consumer.transaction.model.entity.AllDuration;
import com.dianping.cat.consumer.transaction.model.entity.Duration;
import com.dianping.cat.consumer.transaction.model.entity.Graph;
import com.dianping.cat.consumer.transaction.model.entity.Graph2;
import com.dianping.cat.consumer.transaction.model.entity.GraphTrend;
import com.dianping.cat.consumer.transaction.model.entity.Machine;
import com.dianping.cat.consumer.transaction.model.entity.Range;
import com.dianping.cat.consumer.transaction.model.entity.Range2;
import com.dianping.cat.consumer.transaction.model.entity.StatusCode;
import com.dianping.cat.consumer.transaction.model.entity.TransactionName;
import com.dianping.cat.consumer.transaction.model.entity.TransactionReport;
import com.dianping.cat.consumer.transaction.model.entity.TransactionType;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.Map;

public class DefaultNativeParser implements IVisitor {
  private DefaultLinker m_linker;

  public DefaultNativeParser(InputStream in) {
/*  26 */     this.m_linker = new DefaultLinker(true);




    this.m_in = new DataInputStream(in);
  }
  private DataInputStream m_in;

/*  35 */   public static TransactionReport parse(byte[] data) { return parse(new ByteArrayInputStream(data)); }


  public static TransactionReport parse(InputStream in) {
/*  39 */     DefaultNativeParser parser = new DefaultNativeParser(in);
/*  40 */     TransactionReport transactionReport = new TransactionReport();

    try {
/*  43 */       transactionReport.accept(parser);
/*  44 */     } catch (RuntimeException e) {
/*  45 */       if (e.getCause() == null || !(e.getCause() instanceof java.io.EOFException))
      {

/*  48 */         throw e;
      }
    }

/*  52 */     parser.m_linker.finish();
/*  53 */     return transactionReport;
  }



  public void visitAllDuration(AllDuration allDuration) {
    byte tag;
/*  60 */     while ((tag = readTag()) != -1) {
/*  61 */       visitAllDurationChildren(allDuration, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }

  protected void visitAllDurationChildren(AllDuration allDuration, int _field, int _type) {
/*  66 */     switch (_field) {
      case 1:
/*  68 */         allDuration.setValue(readInt());
        break;
      case 2:
/*  71 */         allDuration.setCount(readInt());
        break;
    }
  }



  public void visitDuration(Duration duration) {
    byte tag;
/*  80 */     while ((tag = readTag()) != -1) {
/*  81 */       visitDurationChildren(duration, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }

  protected void visitDurationChildren(Duration duration, int _field, int _type) {
/*  86 */     switch (_field) {
      case 1:
/*  88 */         duration.setValue(readInt());
        break;
      case 2:
/*  91 */         duration.setCount(readInt());
        break;
    }
  }



  public void visitGraph(Graph graph) {
    byte tag;
/* 100 */     while ((tag = readTag()) != -1) {
/* 101 */       visitGraphChildren(graph, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }

  protected void visitGraphChildren(Graph graph, int _field, int _type) {
/* 106 */     switch (_field) {
      case 1:
/* 108 */         graph.setDuration(readInt());
        break;
      case 2:
/* 111 */         graph.setSum(readString());
        break;
      case 3:
/* 114 */         graph.setAvg(readString());
        break;
      case 4:
/* 117 */         graph.setCount(readString());
        break;
      case 5:
/* 120 */         graph.setFails(readString());
        break;
    }
  }



  public void visitGraph2(Graph2 graph2) {
    byte tag;
/* 129 */     while ((tag = readTag()) != -1) {
/* 130 */       visitGraph2Children(graph2, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }

  protected void visitGraph2Children(Graph2 graph2, int _field, int _type) {
/* 135 */     switch (_field) {
      case 1:
/* 137 */         graph2.setDuration(readInt());
        break;
      case 2:
/* 140 */         graph2.setSum(readString());
        break;
      case 3:
/* 143 */         graph2.setAvg(readString());
        break;
      case 4:
/* 146 */         graph2.setCount(readString());
        break;
      case 5:
/* 149 */         graph2.setFails(readString());
        break;
    }
  }



  public void visitGraphTrend(GraphTrend graphTrend) {
    byte tag;
/* 158 */     while ((tag = readTag()) != -1) {
/* 159 */       visitGraphTrendChildren(graphTrend, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }

  protected void visitGraphTrendChildren(GraphTrend graphTrend, int _field, int _type) {
/* 164 */     switch (_field) {
      case 1:
/* 166 */         graphTrend.setDuration(readInt());
        break;
      case 2:
/* 169 */         graphTrend.setSum(readString());
        break;
      case 3:
/* 172 */         graphTrend.setAvg(readString());
        break;
      case 4:
/* 175 */         graphTrend.setCount(readString());
        break;
      case 5:
/* 178 */         graphTrend.setFails(readString());
        break;
    }
  }



  public void visitMachine(Machine machine) {
    byte tag;
/* 187 */     while ((tag = readTag()) != -1) {
/* 188 */       visitMachineChildren(machine, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }

  protected void visitMachineChildren(Machine machine, int _field, int _type) {
/* 193 */     switch (_field) {
      case 1:
/* 195 */         machine.setIp(readString());
        break;
      case 33:
/* 198 */         if (_type == 1) {
/* 199 */           TransactionType type = new TransactionType();

/* 201 */           visitType(type);
/* 202 */           this.m_linker.onType(machine, type); break;
/* 203 */         }  if (_type == 2) {
/* 204 */           for (int i = readInt(); i > 0; i--) {
/* 205 */             TransactionType type = new TransactionType();

/* 207 */             visitType(type);
/* 208 */             this.m_linker.onType(machine, type);
          }
        }
        break;
    }
  }



  public void visitName(TransactionName name) {
    byte tag;
/* 219 */     while ((tag = readTag()) != -1)
/* 220 */       visitNameChildren(name, (tag & 0xFF) >> 2, tag & 0x3); 
  }

  protected void visitNameChildren(TransactionName name, int _field, int _type) {
    GraphTrend graphTrend;
/* 225 */     switch (_field) {
      case 1:
/* 227 */         name.setId(readString());
        break;
      case 2:
/* 230 */         name.setTotalCount(readLong());
        break;
      case 3:
/* 233 */         name.setFailCount(readLong());
        break;
      case 4:
/* 236 */         name.setFailPercent(readDouble());
        break;
      case 5:
/* 239 */         name.setMin(readDouble());
        break;
      case 6:
/* 242 */         name.setMax(readDouble());
        break;
      case 7:
/* 245 */         name.setAvg(readDouble());
        break;
      case 8:
/* 248 */         name.setSum(readDouble());
        break;
      case 9:
/* 251 */         name.setSum2(readDouble());
        break;
      case 10:
/* 254 */         name.setStd(readDouble());
        break;
      case 11:
/* 257 */         name.setSuccessMessageUrl(readString());
        break;
      case 12:
/* 260 */         name.setFailMessageUrl(readString());
        break;
      case 13:
/* 263 */         name.setTps(readDouble());
        break;
      case 14:
/* 266 */         name.setLine95Value(readDouble());
        break;
      case 15:
/* 269 */         name.setLine99Value(readDouble());
        break;
      case 16:
/* 272 */         name.setLine999Value(readDouble());
        break;
      case 17:
/* 275 */         name.setLine90Value(readDouble());
        break;
      case 18:
/* 278 */         name.setLine50Value(readDouble());
        break;
      case 19:
/* 281 */         name.setLine9999Value(readDouble());
        break;
      case 20:
/* 284 */         name.setLongestMessageUrl(readString());
        break;
      case 33:
/* 287 */         if (_type == 1) {
/* 288 */           Range range = new Range();

/* 290 */           visitRange(range);
/* 291 */           this.m_linker.onRange(name, range); break;
/* 292 */         }  if (_type == 2) {
/* 293 */           for (int i = readInt(); i > 0; i--) {
/* 294 */             Range range = new Range();

/* 296 */             visitRange(range);
/* 297 */             this.m_linker.onRange(name, range);
          }
        }
        break;
      case 34:
/* 302 */         if (_type == 1) {
/* 303 */           Duration duration = new Duration();

/* 305 */           visitDuration(duration);
/* 306 */           this.m_linker.onDuration(name, duration); break;
/* 307 */         }  if (_type == 2) {
/* 308 */           for (int i = readInt(); i > 0; i--) {
/* 309 */             Duration duration = new Duration();

/* 311 */             visitDuration(duration);
/* 312 */             this.m_linker.onDuration(name, duration);
          }
        }
        break;
      case 35:
/* 317 */         if (_type == 1) {
/* 318 */           Graph graph = new Graph();

/* 320 */           visitGraph(graph);
/* 321 */           this.m_linker.onGraph(name, graph); break;
/* 322 */         }  if (_type == 2) {
/* 323 */           for (int i = readInt(); i > 0; i--) {
/* 324 */             Graph graph = new Graph();

/* 326 */             visitGraph(graph);
/* 327 */             this.m_linker.onGraph(name, graph);
          }
        }
        break;
      case 36:
/* 332 */         graphTrend = new GraphTrend();

/* 334 */         visitGraphTrend(graphTrend);
/* 335 */         this.m_linker.onGraphTrend(name, graphTrend);
        break;
      case 37:
/* 338 */         if (_type == 1) {
/* 339 */           StatusCode statusCode = new StatusCode();

/* 341 */           visitStatusCode(statusCode);
/* 342 */           this.m_linker.onStatusCode(name, statusCode); break;
/* 343 */         }  if (_type == 2) {
/* 344 */           for (int i = readInt(); i > 0; i--) {
/* 345 */             StatusCode statusCode = new StatusCode();

/* 347 */             visitStatusCode(statusCode);
/* 348 */             this.m_linker.onStatusCode(name, statusCode);
          }
        }
        break;
    }
  }



  public void visitRange(Range range) {
    byte tag;
/* 359 */     while ((tag = readTag()) != -1) {
/* 360 */       visitRangeChildren(range, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }

  protected void visitRangeChildren(Range range, int _field, int _type) {
/* 365 */     switch (_field) {
      case 1:
/* 367 */         range.setValue(readInt());
        break;
      case 2:
/* 370 */         range.setCount(readInt());
        break;
      case 3:
/* 373 */         range.setSum(readDouble());
        break;
      case 4:
/* 376 */         range.setAvg(readDouble());
        break;
      case 5:
/* 379 */         range.setFails(readInt());
        break;
      case 6:
/* 382 */         range.setMin(readDouble());
        break;
      case 7:
/* 385 */         range.setMax(readDouble());
        break;
      case 8:
/* 388 */         range.setLine95Value(readDouble());
        break;
      case 9:
/* 391 */         range.setLine99Value(readDouble());
        break;
      case 10:
/* 394 */         range.setLine999Value(readDouble());
        break;
      case 11:
/* 397 */         range.setLine90Value(readDouble());
        break;
      case 12:
/* 400 */         range.setLine50Value(readDouble());
        break;
      case 13:
/* 403 */         range.setLine9999Value(readDouble());
        break;
    }
  }



  public void visitRange2(Range2 range2) {
    byte tag;
/* 412 */     while ((tag = readTag()) != -1) {
/* 413 */       visitRange2Children(range2, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }

  protected void visitRange2Children(Range2 range2, int _field, int _type) {
/* 418 */     switch (_field) {
      case 1:
/* 420 */         range2.setValue(readInt());
        break;
      case 2:
/* 423 */         range2.setCount(readInt());
        break;
      case 3:
/* 426 */         range2.setSum(readDouble());
        break;
      case 4:
/* 429 */         range2.setAvg(readDouble());
        break;
      case 5:
/* 432 */         range2.setFails(readInt());
        break;
      case 6:
/* 435 */         range2.setMin(readDouble());
        break;
      case 7:
/* 438 */         range2.setMax(readDouble());
        break;
      case 8:
/* 441 */         range2.setLine95Value(readDouble());
        break;
      case 9:
/* 444 */         range2.setLine99Value(readDouble());
        break;
      case 10:
/* 447 */         range2.setLine999Value(readDouble());
        break;
      case 11:
/* 450 */         range2.setLine90Value(readDouble());
        break;
      case 12:
/* 453 */         range2.setLine50Value(readDouble());
        break;
      case 13:
/* 456 */         range2.setLine9999Value(readDouble());
        break;
    }
  }



  public void visitStatusCode(StatusCode statusCode) {
    byte tag;
/* 465 */     while ((tag = readTag()) != -1) {
/* 466 */       visitStatusCodeChildren(statusCode, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }

  protected void visitStatusCodeChildren(StatusCode statusCode, int _field, int _type) {
/* 471 */     switch (_field) {
      case 1:
/* 473 */         statusCode.setId(readString());
        break;
      case 2:
/* 476 */         statusCode.setCount(readLong());
        break;
    }
  }



  public void visitTransactionReport(TransactionReport transactionReport) {
    byte tag;
/* 485 */     if ((tag = readTag()) != -4) {
/* 486 */       throw new RuntimeException(String.format("Malformed payload, expected: %s, but was: %s!", new Object[] { Integer.valueOf(-4), Byte.valueOf(tag) }));
    }

/* 489 */     while ((tag = readTag()) != -1) {
/* 490 */       visitTransactionReportChildren(transactionReport, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }

  protected void visitTransactionReportChildren(TransactionReport transactionReport, int _field, int _type) {
/* 495 */     switch (_field) {
      case 1:
/* 497 */         transactionReport.setDomain(readString());
        break;
      case 2:
/* 500 */         transactionReport.setStartTime(readDate());
        break;
      case 3:
/* 503 */         transactionReport.setEndTime(readDate());
        break;
      case 4:
/* 506 */         if (_type == 1) {
/* 507 */           transactionReport.addDomain(readString()); break;
/* 508 */         }  if (_type == 2) {
/* 509 */           for (int i = readInt(); i > 0; i--) {
/* 510 */             transactionReport.addDomain(readString());
          }
        }
        break;
      case 5:
/* 515 */         if (_type == 1) {
/* 516 */           transactionReport.addIp(readString()); break;
/* 517 */         }  if (_type == 2) {
/* 518 */           for (int i = readInt(); i > 0; i--) {
/* 519 */             transactionReport.addIp(readString());
          }
        }
        break;
      case 33:
/* 524 */         if (_type == 1) {
/* 525 */           Machine machine = new Machine();

/* 527 */           visitMachine(machine);
/* 528 */           this.m_linker.onMachine(transactionReport, machine); break;
/* 529 */         }  if (_type == 2) {
/* 530 */           for (int i = readInt(); i > 0; i--) {
/* 531 */             Machine machine = new Machine();

/* 533 */             visitMachine(machine);
/* 534 */             this.m_linker.onMachine(transactionReport, machine);
          }
        }
        break;
    }
  }



  public void visitType(TransactionType type) {
    byte tag;
/* 545 */     while ((tag = readTag()) != -1)
/* 546 */       visitTypeChildren(type, (tag & 0xFF) >> 2, tag & 0x3); 
  } protected void visitTypeChildren(TransactionType type, int _field, int _type) {
    int i;
    Map<String, String> dynamicAttribute;
    GraphTrend graphTrend;
/* 551 */     switch (_field) {
      case 1:
/* 553 */         type.setId(readString());
        break;
      case 2:
/* 556 */         type.setTotalCount(readLong());
        break;
      case 3:
/* 559 */         type.setFailCount(readLong());
        break;
      case 4:
/* 562 */         type.setFailPercent(readDouble());
        break;
      case 5:
/* 565 */         type.setMin(readDouble());
        break;
      case 6:
/* 568 */         type.setMax(readDouble());
        break;
      case 7:
/* 571 */         type.setAvg(readDouble());
        break;
      case 8:
/* 574 */         type.setSum(readDouble());
        break;
      case 9:
/* 577 */         type.setSum2(readDouble());
        break;
      case 10:
/* 580 */         type.setStd(readDouble());
        break;
      case 11:
/* 583 */         type.setSuccessMessageUrl(readString());
        break;
      case 12:
/* 586 */         type.setFailMessageUrl(readString());
        break;
      case 13:
/* 589 */         type.setTps(readDouble());
        break;
      case 14:
/* 592 */         type.setLine95Value(readDouble());
        break;
      case 15:
/* 595 */         type.setLine99Value(readDouble());
        break;
      case 16:
/* 598 */         type.setLine999Value(readDouble());
        break;
      case 17:
/* 601 */         type.setLine90Value(readDouble());
        break;
      case 18:
/* 604 */         type.setLine50Value(readDouble());
        break;
      case 19:
/* 607 */         type.setLine9999Value(readDouble());
        break;
      case 20:
/* 610 */         type.setLongestMessageUrl(readString());
        break;
      case 33:
/* 613 */         if (_type == 1) {
/* 614 */           TransactionName name = new TransactionName();

/* 616 */           visitName(name);
/* 617 */           this.m_linker.onName(type, name); break;
/* 618 */         }  if (_type == 2) {
/* 619 */           for ( i = readInt(); i > 0; i--) {
/* 620 */             TransactionName name = new TransactionName();

/* 622 */             visitName(name);
/* 623 */             this.m_linker.onName(type, name);
          }
        }
        break;
      case 34:
/* 628 */         if (_type == 1) {
/* 629 */           Graph2 graph2 = new Graph2();

/* 631 */           visitGraph2(graph2);
/* 632 */           this.m_linker.onGraph2(type, graph2); break;
/* 633 */         }  if (_type == 2) {
/* 634 */           for ( i = readInt(); i > 0; i--) {
/* 635 */             Graph2 graph2 = new Graph2();

/* 637 */             visitGraph2(graph2);
/* 638 */             this.m_linker.onGraph2(type, graph2);
          }
        }
        break;
      case 35:
/* 643 */         graphTrend = new GraphTrend();

/* 645 */         visitGraphTrend(graphTrend);
/* 646 */         this.m_linker.onGraphTrend(type, graphTrend);
        break;
      case 36:
/* 649 */         if (_type == 1) {
/* 650 */           Range2 range2 = new Range2();

/* 652 */           visitRange2(range2);
/* 653 */           this.m_linker.onRange2(type, range2); break;
/* 654 */         }  if (_type == 2) {
/* 655 */           for ( i = readInt(); i > 0; i--) {
/* 656 */             Range2 range2 = new Range2();

/* 658 */             visitRange2(range2);
/* 659 */             this.m_linker.onRange2(type, range2);
          }
        }
        break;
      case 63:
/* 664 */         dynamicAttribute = type.getDynamicAttributes();

/* 666 */         for (i = readInt(); i > 0; i--) {
/* 667 */           String key = readString();
/* 668 */           String value = readString();

/* 670 */           dynamicAttribute.put(key, value);
        }
        break;
    }
  }

  private Date readDate() {
    try {
/* 678 */       return new Date(readVarint(64));
/* 679 */     } catch (IOException e) {
/* 680 */       throw new RuntimeException(e);
    }
  }

  private double readDouble() {
    try {
/* 686 */       return Double.longBitsToDouble(readVarint(64));
/* 687 */     } catch (IOException e) {
/* 688 */       throw new RuntimeException(e);
    }
  }

  private int readInt() {
    try {
/* 694 */       return (int)readVarint(32);
/* 695 */     } catch (IOException e) {
/* 696 */       throw new RuntimeException(e);
    }
  }

  private long readLong() {
    try {
/* 702 */       return readVarint(64);
/* 703 */     } catch (IOException e) {
/* 704 */       throw new RuntimeException(e);
    }
  }

  private String readString() {
    try {
/* 710 */       return this.m_in.readUTF();
/* 711 */     } catch (IOException e) {
/* 712 */       throw new RuntimeException(e);
    }
  }

  private byte readTag() {
    try {
/* 718 */       return this.m_in.readByte();
/* 719 */     } catch (IOException e) {
/* 720 */       throw new RuntimeException(e);
    }
  }

  protected long readVarint(int length) throws IOException {
/* 725 */     int shift = 0;
/* 726 */     long result = 0L;

/* 728 */     while (shift < length) {
/* 729 */       byte b = this.m_in.readByte();
/* 730 */       result |= (b & 0x7F) << shift;
/* 731 */       if ((b & 0x80) == 0) {
/* 732 */         return result;
      }
/* 734 */       shift += 7;
    }

/* 737 */     throw new RuntimeException("Malformed variable int " + length + "!");
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-consumer-3.0.0.jar!/com/dianping/cat/consumer/transaction/model/transform/DefaultNativeParser.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */